<?php

declare(strict_types=1);

namespace App\Model\CommodityModel;

use App\Model\BaseModel\BaseCommodityModel;
use Hyperf\DbConnection\Db;

class StockmappleinfoModel extends BaseCommodityModel
{
    protected $table = 'stockmapperinfo';
    
    //指定写入字段
    protected $fillable = [
        
    ];
    
    //指定字段展示类型
    protected $casts = [
        'goods_id' => 'string',
        'store_id' => 'string',
    ];
    
    /**
     * 获取商户授权商品信息
     * @param number $bid
     */
    public static function getWareHouseGoodsInfoLists() 
    {
        return self::query()
        ->join('skuinfo','stockmapperinfo.SkuID','=','skuinfo.ID')
        ->join('commoditymapperinfo','commoditymapperinfo.ID','=','skuinfo.CommodityID')
        ->join('warehouseinfo','warehouseinfo.ID','=','stockmapperinfo.WarehouseID')
        ->join('brandinfo','brandinfo.ID','=','commoditymapperinfo.BrandID')
        ->where([
            ['stockmapperinfo.IsDeleted','=',0],
            ['stockmapperinfo.Number','>',0],
            ['commoditymapperinfo.IsForbidden','=',0],
            ['commoditymapperinfo.IsDeleted','=',0],
            ['commoditymapperinfo.ImageData','<>','1'],
            ['commoditymapperinfo.Description','<>','1'],
            ['skuinfo.IsForbidden','=',0],
            ['skuinfo.IsDeleted','=',0],
            ['skuinfo.CostPrice','>',0],
            ['warehouseinfo.IsDeleted','=',0],
            ['warehouseinfo.ExamineState','=',1],
        ])
        ->select([
            Db::raw('DISTINCT skuinfo.ID as goods_id'),
            Db::raw('skuinfo.SKUCode as skucode'),
            Db::raw('skuinfo.BarCode as barcode'),
            Db::raw('commoditymapperinfo.CommodityName as goods_name'),
            Db::raw('commoditymapperinfo.ImageData as image'),
            Db::raw('commoditymapperinfo.CommodityType as goods_type'),
            Db::raw('brandinfo.BrandName as brand_name'),
            Db::raw('stockmapperinfo.WarehouseID as store_id')
        ])
        ->orderBy('stockmapperinfo.ID','asc')
        ->paginate(self::PAGE_LIMIT);
    }
}
